Skip to content

expand check to match Rails generated Dockerfiles #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2025

Conversation

rubys
Copy link
Collaborator

@rubys rubys commented Feb 25, 2025

An example:

ARG RUBY_VERSION=3.4.2
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

An example:
```
ARG RUBY_VERSION=3.4.2
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
```
@rubys rubys requested a review from albus522 February 25, 2025 13:56
Copy link
Collaborator

@albus522 albus522 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with possible suggestion

@@ -418,7 +418,7 @@ def generate_app
# Older versions no longer release new images
matching_ruby = [">= 3.4.2", "~> 3.3.7", "~> 3.2.7", "~> 3.1.7"].any? { |v| Gem::Requirement.new(v).satisfied_by?(Gem.ruby_version) }
# Only slim and alpine are missing libyaml-dev/yaml-dev
matching_image = /FROM ruby:.+-(alpine|slim)/i.match?(dockerfile)
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

Suggested change
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
matching_image = /FROM .*\/ruby:.+-(alpine|slim)/i.match?(dockerfile)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That suggestion is wrong

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
# https://rubular.com/r/Jb4LEfrMSmxkp9
matching_image = /FROM (.*\/)?ruby:(.+-)?(alpine|slim)/i.match?(dockerfile)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do the trick:

@@ -418,7 +418,7 @@ class DockerfileGenerator < Rails::Generators::Base
       # Older versions no longer release new images
       matching_ruby = [">= 3.4.2", "~> 3.3.7", "~> 3.2.7", "~> 3.1.7"].any? { |v| Gem::Requirement.new(v).satisfied_by?(Gem.ruby_version) }
       # Only slim and alpine are missing libyaml-dev/yaml-dev
-      matching_image = /FROM .*ruby:.+-(alpine|slim)/i.match?(dockerfile)
+      matching_image = /FROM (|.+/)ruby:.+-(alpine|slim)/i.match?(dockerfile)

@albus522
Copy link
Collaborator

Did you notice my updated suggestion with test cases?

@rubys rubys merged commit 499267a into main Feb 25, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants